const toString = Object.prototype.toString;

export function is(val: unknown, type: string) {
    return toString.call(val) === `[object ${type}]`;
}

export function isString(val: unknown): val is string {
    return is(val, 'string');
}

export function isFun(val: any): val is (...arg: any[]) => void {
    return val !== null && is(val, 'Function');
}

export function isArray(val: any): val is any[] {
    return is(val, 'Array');
}

export function isWindow(val: any): val is Window {
    return is(val, 'Window');
}
export function isUrl(path: string) {
    const reg =
        /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
    return reg.test(path);
}
